{extend name="base:base" /}
{block name="body"}
<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class=""><a href="{:Url::build('AuthManager/access',['group_id'=>$group_id])}">访问授权</a></li>
        <li class="layui-this"><a href="{:Url::build('AuthManager/user',['group_id'=>$group_id])}">用户授权</a></li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-form">
            <div class="layui-btn-group">
                <a class="layui-btn layui-btn-normal addToGroup" href="javascript:void(0);">增加用户</a>
            </div>
            <div class="layui-inline">
                <select name="group_id" lay-filter="group_id">
                    <option>请选择用户组</option>
                    {notempty name="auth_group"}
                        {volist name="auth_group" id="vo"}
                            <option value="{$vo['id']}">{$vo.title}</option>
                        {/volist}
                    {/notempty}
                </select>
            </div>
        </div>
        <div class="layui-tab-item layui-show">
            <table class="layui-hide" id="user" lay-filter="user"></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="statusTpl">
    {{#  if(d.status == 1){return "正常"; } else {return "禁用";} }}
</script>
<script type="text/html" id="operating">
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="relieve">解除授权</a>
</script>
<script type="text/javascript">
    UrlHighlight("{:Url::build('AuthManager/index')}");
    setChoose('group_id', "{$group_id ?? ''}");
    //监听提交
    layui.use(['jquery', 'form','table', 'layer'], function () {
        table_reload = layui.table.render({
            elem: '#user',
            url: "{:Url::build('AuthManager/userJson')}",
            where:{group_id:"{$group_id}"},
            page: true,
            method: 'post',
            limit: 10,
            id: "ids",
            loading: false,
            cols: [[ //标题栏
                {checkbox: true},
                {field: 'uid', title: 'UID', width: 100},
                {field: 'nickname', title: '昵称', width: 300},
                {field: 'last_login_time', title: '最后登录时间', width: 250},
                {field: 'last_login_ip', title: '最后登录IP', width: 250},
                {field: 'status', title: '状态', width: 200, templet: '#statusTpl'},
                {fixed: 'right', title: '操作', align: 'center', width: 200, toolbar: '#operating'},
            ]]
        });

        //监听工具条
        layui.table.on('tool(user)', function (obj) {
            switch (obj.event) {
                case "relieve":
                    layui.layer.confirm('确定执行该操作吗?', function (index) {
                        layui.layer.close(index);
                        layui.$.post("{:Url::build('AuthManager/removeFromGroup')}", {
                            group_id: "{$group_id}",
                            uid: obj.data.uid
                        }, function (data) {
                            if (data.code !== 1) {
                                return alert_msg(data.msg, 0)
                            };
                            alert_msg(data.msg, 1);
                            setTimeout(function () {
                                table_reload.reload();
                            }, 1500);
                        });
                    });
                    break;
                default:
                    layui.layer.msg('噢，天啊！你点了什么？');
                    break;
            }
        });

        layui.form.on('submit(group)', function (data) {
            layui.$.post(data.form.action, data.field, function (info) {
                status_load(info, data.elem);
            })
            return false;
        });

        layui.form.on('select(group_id)',function (event) {
            layui.layer.load(2);
            location.href =createURL("{:Url::build('AuthManager/user')}",{group_id:event.value});
        });

        layui.$('.addToGroup').on('click', function () {
            layui.layer.open({
                type: 1,
                title: "添加用户",
                area: '550px',
                offset: '300px',
                content: layui.$('#addUsertpl')
            });
        })
    })
</script>
<div id="addUsertpl" style="display: none;">
    <form class="layui-form" style="margin: 15px;" action="{:Url::build('AuthManager/addToGroup')}" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label w-0">用户UID</label>
            <div class="layui-input-inline">
                <input type="text" name="uid" lay-verify="required" placeholder="多个UID用英文逗号分隔"
                       class="layui-input">
                <input type="hidden" name="group_id" value="{$group_id}">
            </div>
            <div class="layui-inline">
                <button class="layui-btn" lay-submit="" lay-filter="group">确定</button>
            </div>
        </div>
    </form>
</div>
{/block}